Skip to content

fix(openai-agents): capture system instructions from Response object#4284

Closed
nagkumar91 wants to merge 1 commit into
open-telemetry:mainfrom
nagkumar91:fix/4188-system-instructions
Closed

fix(openai-agents): capture system instructions from Response object#4284
nagkumar91 wants to merge 1 commit into
open-telemetry:mainfrom
nagkumar91:fix/4188-system-instructions

Conversation

@nagkumar91

Copy link
Copy Markdown
Contributor

Description

Fixes #4188

Problem: When using the Responses API (default in OpenAI Agents SDK), agent instructions are passed as a separate parameter to responses.create(instructions=...) — NOT as role: "system" messages in the input. The Response object stores these on its .instructions attribute. However, _collect_system_instructions() only scans input messages for role in {"system", "ai"}, so instructions were never captured in gen_ai.system_instructions.

Fix: In _build_content_payload() for ResponseSpanData, after the existing input-message-based system instruction collection, add a fallback that reads response.instructions:

if capture_system and not payload.system_instructions:
    response = getattr(span_data, "response", None)
    instructions = getattr(response, "instructions", None)
    if isinstance(instructions, str) and instructions:
        payload.system_instructions = [{"type": "text", "content": instructions}]

This works for both Responses API and Chat Completions API (which already worked via input messages).

Testing: Added unit test with mock Response object containing .instructions.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

…pen-telemetry#4188)

When using the Responses API, instructions are passed separately and
stored on response.instructions rather than as role="system" input
messages. This adds a fallback to read response.instructions for
gen_ai.system_instructions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@nagkumar91 nagkumar91 requested a review from a team as a code owner March 3, 2026 18:04
@tammy-baylis-swi tammy-baylis-swi moved this to Ready for review in Python PR digest Mar 3, 2026
@nagkumar91

Copy link
Copy Markdown
Contributor Author

Closing in favor of existing PR #4196 by @adammw which already addresses this issue.

@nagkumar91 nagkumar91 closed this Mar 3, 2026
@github-project-automation github-project-automation Bot moved this from Ready for review to Done in Python PR digest Mar 3, 2026
@nagkumar91 nagkumar91 deleted the fix/4188-system-instructions branch March 3, 2026 23:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[OpenAI Agents] System prompt/instructions do not show in trace

2 participants